package views;

import views.panels.PanelGeneral;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import logicBusiness.AreaBL;
import logicBusiness.AsignaturaBL;
import javax.swing.SpinnerNumberModel;
import javax.swing.JOptionPane;
//import business.LogroBO;
import logicBusiness.CursoBL;
import javax.swing.table.DefaultTableModel;
import logicBusiness.EstudianteBL;
import models.Estudiante;
import javax.swing.ImageIcon;
import logicBusiness.EstudianteLogroBL;
//import models.EstudianteLogro;

/**
 *
 * @author vanessa
 */
public class InterfazRegistrarCalificaciones extends javax.swing.JFrame {

    private AreaBL areaBo = new AreaBL();
    private AsignaturaBL asignaturaBo = new AsignaturaBL();
    // private LogroBO logroBo = new LogroBO();
    private CursoBL cursoBo = new CursoBL();
    private EstudianteBL estudianteBo = new EstudianteBL();
    private EstudianteLogroBL estudianteLogroBo = new EstudianteLogroBL();
    private final ImageIcon icono;

    /** Creates new form InterfazRegistrarCalificaciones */
    public InterfazRegistrarCalificaciones() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        icono = new ImageIcon(getClass().getResource("/views/images/icon.gif"));
        this.setIconImage(icono.getImage());
        cargarListaGrados();
        cargarListaAreas();
        cargarListaAsignaturas();
        cargarPeriodo();
        cargarComboPeriodo();
        cargarComboPeriodoConsulta();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        CBGrados = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        CBAreas = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        CTEntradaLogro = new javax.swing.JTextField();
        BRegistrarLogro = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        SPeriodo = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        CBAsignaturas = new javax.swing.JComboBox();
        CBCursos = new javax.swing.JComboBox();
        SPCalificaciones = new javax.swing.JScrollPane();
        TCalificaciones = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        SPLogros = new javax.swing.JScrollPane();
        TLogros = new javax.swing.JTable();
        BRegistrarCalificaciones = new javax.swing.JButton();
        BConsultarCali = new javax.swing.JButton();
        BSalir = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        CBPeriodo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        REliminarLogro = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        CBPeriodoConsulta = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        BActualizarDescripcion = new javax.swing.JButton();

        setTitle("Registrar Calificaciones");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jLabel1.setText("Buscar Asignatura:");

        jLabel3.setText("Grado");

        CBGrados.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBGrados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBGradosActionPerformed(evt);
            }
        });

        jLabel4.setText("Area");

        CBAreas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBAreas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBAreasActionPerformed(evt);
            }
        });

        jLabel7.setText("Digite el nuevo Logro:");

        BRegistrarLogro.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BRegistrarLogro.setText("Registrar Logro");
        BRegistrarLogro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegistrarLogroActionPerformed(evt);
            }
        });

        jLabel8.setText("Periodo:");

        jLabel2.setText("Asignatura:");

        CBAsignaturas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBAsignaturas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBAsignaturasActionPerformed(evt);
            }
        });

        CBCursos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBCursosActionPerformed(evt);
            }
        });

        TCalificaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Nombre del Estudiante"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        TCalificaciones.setColumnSelectionAllowed(true);
        SPCalificaciones.setViewportView(TCalificaciones);
        TCalificaciones.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        jLabel6.setText("Ahora registre las calificaciones por curso:");

        TLogros.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Nro. del Logro", "Codigo del Logro", "Logro", "Periodo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        TLogros.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        SPLogros.setViewportView(TLogros);
        TLogros.getColumnModel().getColumn(0).setPreferredWidth(100);
        TLogros.getColumnModel().getColumn(1).setPreferredWidth(100);
        TLogros.getColumnModel().getColumn(2).setPreferredWidth(700);

        BRegistrarCalificaciones.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BRegistrarCalificaciones.setText("Registrar Calificaciones");
        BRegistrarCalificaciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegistrarCalificacionesActionPerformed(evt);
            }
        });

        BConsultarCali.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BConsultarCali.setText("Consultar Calificaciones");
        BConsultarCali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BConsultarCaliActionPerformed(evt);
            }
        });

        BSalir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BSalir.setText("Salir");
        BSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSalirActionPerformed(evt);
            }
        });

        jLabel5.setText("Y por periodo:");

        CBPeriodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBPeriodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBPeriodoActionPerformed(evt);
            }
        });

        jLabel9.setText("Puede eliminar un logro seleccionado de la tabla");

        REliminarLogro.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        REliminarLogro.setText("Eliminar Logro");
        REliminarLogro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                REliminarLogroActionPerformed(evt);
            }
        });

        jLabel10.setText("Consultar los Logros por periodo:");

        CBPeriodoConsulta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBPeriodoConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBPeriodoConsultaActionPerformed(evt);
            }
        });

        jLabel11.setText("Tambien puede cambiar la descripción de los logros:");

        BActualizarDescripcion.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BActualizarDescripcion.setText("Cambiar Descripción");
        BActualizarDescripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BActualizarDescripcionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(BRegistrarCalificaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(85, 85, 85)
                        .addComponent(BConsultarCali, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                        .addComponent(BSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(SPCalificaciones, javax.swing.GroupLayout.DEFAULT_SIZE, 987, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CBGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CBAreas, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addGap(2, 2, 2)
                        .addComponent(CBAsignaturas, 0, 663, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(CTEntradaLogro, javax.swing.GroupLayout.DEFAULT_SIZE, 875, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(SPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 634, Short.MAX_VALUE)
                                .addComponent(BRegistrarLogro, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(SPLogros, javax.swing.GroupLayout.DEFAULT_SIZE, 987, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel9)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(CBCursos, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(REliminarLogro, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BActualizarDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
                        .addGap(183, 183, 183)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(CBPeriodo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(CBPeriodoConsulta, 0, 121, Short.MAX_VALUE))))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(CBGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CBAsignaturas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(CBAreas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(CTEntradaLogro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(BRegistrarLogro)
                    .addComponent(SPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SPLogros, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(REliminarLogro)
                    .addComponent(CBPeriodoConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BActualizarDescripcion)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(CBCursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CBPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addComponent(SPCalificaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BRegistrarCalificaciones)
                    .addComponent(BSalir)
                    .addComponent(BConsultarCali))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BConsultarCaliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BConsultarCaliActionPerformed
        // TODO add your handling code here:
        InterfazConsultarCalificaciones interfazConsultarCalificaciones = new InterfazConsultarCalificaciones();
        interfazConsultarCalificaciones.setVisible(true);

    }//GEN-LAST:event_BConsultarCaliActionPerformed

    private void BSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BSalirActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_BSalirActionPerformed

    private void cargarListaAreas() {
        List l = areaBo.consultarAreas();
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBAreas.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccionar");
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i));
        }
        CBAreas.setModel(modelo);
    }

    private void cargarListaAsignaturas() {
        List lista = asignaturaBo.consultarAsignaturasAreaGrado(CBAreas.getSelectedItem() + "", CBGrados.getSelectedIndex() - 1);
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBAsignaturas.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < lista.size(); i++) {
            modelo.addElement(lista.get(i));
        }
        CBAsignaturas.setModel(modelo);
    }

    private void cargarComboPeriodo() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBPeriodo.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("Primero");
        modelo.addElement("Segundo");
        modelo.addElement("Tercero");
        modelo.addElement("Cuarto");
    }

    private void cargarComboPeriodoConsulta() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBPeriodoConsulta.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("Primero");
        modelo.addElement("Segundo");
        modelo.addElement("Tercero");
        modelo.addElement("Cuarto");
    }

    private void cargarListaCursosGrado(Integer idGrado) {
        List lista = cursoBo.consultarCursosGrado(idGrado);
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBCursos.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < lista.size(); i++) {
            modelo.addElement(lista.get(i));
        }
        CBCursos.setModel(modelo);
    }

    private void cargarListaGrados() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBGrados.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("0.  Transicion");
        modelo.addElement("1.  Primero");
        modelo.addElement("2.  Segundo");
        modelo.addElement("3.  Tercero");
        modelo.addElement("4.  Cuarto");
        modelo.addElement("5.  Quinto");
        modelo.addElement("6.  Sexto");
        modelo.addElement("7.  Séptimo");
        modelo.addElement("8.  Octavo");
        modelo.addElement("9.  Noveno");
        modelo.addElement("10.  Decimo");
        modelo.addElement("11.  Once");

    }

    private void cargarPeriodo() {
        SpinnerNumberModel modelo = (SpinnerNumberModel) SPeriodo.getModel();
        modelo.setMaximum(4);
        modelo.setMinimum(0);
        SPeriodo.setModel(modelo);
    }

    private void cargarListaLogros(Integer idAsignatura) {
        DefaultTableModel modelo = (DefaultTableModel) TLogros.getModel();
        List lista;

        int a = modelo.getRowCount();
        for (int i = 0; i < a; i++) {
            modelo.removeRow(0);
        }
        Object[] fila = new Object[4];
        Object[] dato = new Object[3];
        // lista = logroBo.consultarListaLogros(idAsignatura, Integer.parseInt(periodoSpin.getValue() + ""));
       /* for (int i = 0; i < lista.size(); i++) {
        dato = (Object[]) lista.get(i);
        fila[1] = dato[0];
        fila[2] = dato[1];
        fila[3] = dato[2];
        fila[0] = i + 1;
        modelo.addRow(fila);
        }*/
        TLogros.setModel(modelo);

    }

    private void cargarListaLogros(Integer idAsignatura, Integer periodo) {
        DefaultTableModel modelo = (DefaultTableModel) TLogros.getModel();
        List lista;

        int a = modelo.getRowCount();
        for (int i = 0; i < a; i++) {
            modelo.removeRow(0);
        }
        Object[] fila = new Object[4];
        Object[] dato = new Object[3];
        // lista = logroBo.consultarListaLogros(idAsignatura, periodo);
        /*for (int i = 0; i < lista.size(); i++) {
        dato = (Object[]) lista.get(i);
        fila[1] = dato[0];
        fila[2] = dato[1];
        fila[3] = dato[2];
        fila[0] = i + 1;
        modelo.addRow(fila);
        }*/
        TLogros.setModel(modelo);

    }

    private void CBGradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBGradosActionPerformed
        // TODO add your handling code here:
        cargarListaAsignaturas();
        cargarListaCursosGrado(CBGrados.getSelectedIndex() - 1);
    }//GEN-LAST:event_CBGradosActionPerformed

    private void CBAreasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBAreasActionPerformed
        cargarListaAsignaturas();
    }//GEN-LAST:event_CBAreasActionPerformed

    private void BRegistrarLogroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegistrarLogroActionPerformed
        // TODO add your handling code here:
//        List<Estudiante> estudiantes = estudianteBo.encontrarEstudiantesAsignadosAGrado((CBGrados.getSelectedIndex() - 1) + "");
        int a = TLogros.getRowCount();
        int b = 0;
        int idLogro = 0;
        for (int i = 0; i < a; i++) {
            if (TLogros.getValueAt(i, 2).equals(CTEntradaLogro.getText())) {
                b = 1;
                i = a + 1;
            }
        }

        if ((CBAsignaturas.getSelectedItem() + "").equals("") || CTEntradaLogro.getText().equals("") || Integer.parseInt(SPeriodo.getValue().toString()) == 0) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar una asignatura, digitar un logro y seleccionar un periodo para registrarlo", "Registro fallido", JOptionPane.ERROR_MESSAGE);
        } else if (b == 1) {
            JOptionPane.showMessageDialog(this, "Logros con la misma descripcion", "Registro fallido", JOptionPane.ERROR_MESSAGE);

        } else if ((CBCursos.getSelectedItem() + "").equals("")) {
            JOptionPane.showMessageDialog(this, "Seleccione un curso porfavor", "Registro fallido", JOptionPane.ERROR_MESSAGE);
        } else {
            // idLogro = logroBo.crearLogro(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), Integer.parseInt(periodoSpin.getValue().toString()), entradaLogro.getText());
            cargarListaLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""));
            CTEntradaLogro.setText("");
//            estudianteLogroBo.crearEstudianteLogro(estudiantes, idLogro, null);
        }

    }//GEN-LAST:event_BRegistrarLogroActionPerformed

    private void CBAsignaturasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBAsignaturasActionPerformed
        CTEntradaLogro.setText("");
        cargarListaLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""));

    }//GEN-LAST:event_CBAsignaturasActionPerformed

    private void REliminarLogroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_REliminarLogroActionPerformed
        int a = TLogros.getSelectedRow();
        //logroBo.borrarLogro(Integer.parseInt(tablaLogros.getValueAt(a, 1) + ""));
        cargarListaLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""));
    }//GEN-LAST:event_REliminarLogroActionPerformed

    private void CBPeriodoConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBPeriodoConsultaActionPerformed
        cargarListaLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""), CBPeriodoConsulta.getSelectedIndex());
    }//GEN-LAST:event_CBPeriodoConsultaActionPerformed

    private void CBPeriodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBPeriodoActionPerformed
        inicializarTablaCalificaciones();
    }//GEN-LAST:event_CBPeriodoActionPerformed

    private void inicializarTablaCalificaciones() {
//        List<Estudiante> listaEstudiantes = estudianteBo.encontrarEstudiantesAsignadosACurso(CBCursos.getSelectedItem() + "");
//        int numfilas = listaEstudiantes.size();
        // List listaLogros = logroBo.consultarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodo.getSelectedIndex());
        //int numcolumnas = listaLogros.size();
//        List<EstudianteLogro> listaEstLog = estudianteLogroBo.consultarListaEstLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""));
        // String nombreColumna[] = new String[numcolumnas + 2];
        /*for (int i = 0; i < numcolumnas + 2; i++) {
        if (i == 0) {
        nombreColumna[i] = "Doc. Identidad";
        } else if (i == 1) {
        nombreColumna[i] = "Nombre del Estudiante";
        } else {
        nombreColumna[i] = "L" + (i - 1);
        }
        }*/

        /* tablaCalificaciones.setModel((TableModel) new DefaultTableModelImpl(
        new Object[numfilas][numcolumnas + 2],
        nombreColumna));*/
        Object[] dato = new Object[3];

//        for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {
////            this.TCalificaciones.setValueAt(listaEstudiantes.get(indicefilas).getDocEstudiante(), indicefilas, 0);
////            this.TCalificaciones.setValueAt(listaEstudiantes.get(indicefilas).getNombreEst() + " " + listaEstudiantes.get(indicefilas).getApellidoEst(), indicefilas, 1);
//
//            /* for (int indicelogros = 2; indicelogros < numcolumnas + 2; indicelogros++) {
//            dato = (Object[]) listaLogros.get(indicelogros - 2);
//            this.tablaCalificaciones.setValueAt(estudianteLogroBo.encontrarCalificacionLogroEst(listaEstudiantes.get(indicefilas).getIdEstudiante() + "", dato[0] + ""), indicefilas, indicelogros);
//            }*/
//        }
    }

    private void CBCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBCursosActionPerformed
        inicializarTablaCalificaciones();
    }//GEN-LAST:event_CBCursosActionPerformed

    private void BRegistrarCalificacionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegistrarCalificacionesActionPerformed
//Actualizar los datos de la tabla tablaCalificaciones en la BD
        boolean cal;
//        List<Estudiante> listaEstudiantes = estudianteBo.encontrarEstudiantesAsignadosACurso(CBCursos.getSelectedItem() + "");
//        int numfilas = listaEstudiantes.size();
        // List listaLogros = logroBo.consultarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodo.getSelectedIndex());
        // int numcolumnas = listaLogros.size();
        Object[] dato = new Object[3];
//        for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {
//
//            /* for (int indicelogros = 2; indicelogros < numcolumnas + 2; indicelogros++) {
//            dato = (Object[]) listaLogros.get(indicelogros - 2);
//            estudianteLogroBo.actualizarCalificaciones(listaEstudiantes.get(indicefilas).getIdEstudiante()+"",dato[0]+"",this.tablaCalificaciones.getValueAt(indicefilas, indicelogros).toString());
//
//            }*/
//        }




    }//GEN-LAST:event_BRegistrarCalificacionesActionPerformed

    private void BActualizarDescripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BActualizarDescripcionActionPerformed
        // TODO add your handling code here:
        int x = TLogros.getRowCount();
        int validar = 0;

        for (int i = 0; i < x; i++) {
            String nuevaDescripcion = (String) TLogros.getValueAt(i, 2);
            Integer idLogro = (Integer) TLogros.getValueAt(i, 1);
            // validar = logroBo.actualizarLogro(idLogro, nuevaDescripcion);
            if (validar == 0) {
                System.out.println("ErrorBD");
            }

        }
        cargarListaLogros(asignaturaBo.encontrarAsignatura(CBAsignaturas.getSelectedItem() + ""), CBPeriodoConsulta.getSelectedIndex());
    }//GEN-LAST:event_BActualizarDescripcionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazRegistrarCalificaciones().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BActualizarDescripcion;
    private javax.swing.JButton BConsultarCali;
    private javax.swing.JButton BRegistrarCalificaciones;
    private javax.swing.JButton BRegistrarLogro;
    private javax.swing.JButton BSalir;
    private javax.swing.JComboBox CBAreas;
    private javax.swing.JComboBox CBAsignaturas;
    private javax.swing.JComboBox CBCursos;
    private javax.swing.JComboBox CBGrados;
    private javax.swing.JComboBox CBPeriodo;
    private javax.swing.JComboBox CBPeriodoConsulta;
    private javax.swing.JTextField CTEntradaLogro;
    private javax.swing.JButton REliminarLogro;
    private javax.swing.JScrollPane SPCalificaciones;
    private javax.swing.JScrollPane SPLogros;
    private javax.swing.JSpinner SPeriodo;
    private javax.swing.JTable TCalificaciones;
    private javax.swing.JTable TLogros;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables
}
